package com.link.base.base.dingtalk.controller;

import com.alibaba.fastjson.JSONArray;
import com.link.base.base.dingtalk.service.DingTalkService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/link/dingtalk")
public class DingTalkController {

    @Resource
    DingTalkService  dingTalkService;

    /**
     * 获取dingTalk的鉴权信息
     *
     * @param request
     * @return RespDTO
     * @throws Exception
     */
    @RequestMapping(method = {RequestMethod.POST}, value = "/getDingConfig")
    public Map<String,Object> getDingConfig(@RequestParam String url,@RequestParam String jsApiList,
                                            HttpServletRequest request) throws Exception {
        Map<String,Object> result = new HashMap<>();
        try {
            JSONArray jsonArray = JSONArray.parseArray(jsApiList);
            result = dingTalkService.getDingConfig(url,jsonArray);

        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
